package com.future.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.future.domain.Lost;
import com.future.dto.LostDto;
import com.future.dto.MsgDto;
import com.future.service.LostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: 何晔
 * @time: 2022/6/20 18:14
 */
@RestController
@RequestMapping("lost")
public class LostController {
    @Autowired
private LostService lostService;

    @RequestMapping("selectLost")
    public Page<Lost> findLost( LostDto lostDto){
        QueryWrapper<Lost> queryWrapper=new QueryWrapper<>();

        if(lostDto.getLostname()!=null&lostDto.getLostname()!=""){
        queryWrapper.like("lostname",lostDto.getLostname());

        }
        if(lostDto.getLoststatus()!=null&lostDto.getLoststatus()!=""){
              queryWrapper.eq("loststatus",lostDto.getLoststatus());

        }

        Page<Lost> page=new Page<>(lostDto.getCurrent(),lostDto.getSize());
         this.lostService.page(page,queryWrapper);
         return page;
    }

    @RequestMapping("saveLost")
    public MsgDto addLost(@RequestBody Lost lost){
        lost.setLostpublishtime(new Date());
    this.lostService.save(lost);
    return  new MsgDto(true,"添加成功");
    }

    @RequestMapping("updateLost")
    public MsgDto updateLost(@RequestBody Lost lost){

          lost.setLostupdatetime(new Date());
        this.lostService.updateById(lost);
        return  new MsgDto(true,"修改成功");
    }

    @RequestMapping("lostone")
    public Lost lostone(int lostid){
     return this.lostService.getById(lostid);
    }

}
